<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Administrateur
 *
 * @author admin
 */
class Administrateur {
    
    
   
    function __construct() {
         $db = mysql_connect("localhost","root","root");
         mysql_selectdb("projet2", $db);
        
         
        }
    
    public function ModifierAdmin() {
      
     $sqlaff = mysql_query("select * from administrateur");
     $rowaff = mysql_fetch_array($sqlaff);
     
     
     
        if (isset($_POST['loginadmin'])&& isset($_POST['motdepasseadmin']) && isset($_POST['nomadmin']) && isset($_POST['prenomadmin']))
        {   
       
            $login = $_POST['loginadmin'];
            $motdepasse = $_POST['motdepasseadmin'];
            $nom = $_POST['nomadmin'];
            $prenom = $_POST['prenomadmin'];
            
            $sql = mysql_query("update administrateur set login='$login',motdepasse='$motdepasse',nom='$nom',prenom='$prenom'");
            if ($sql){
                echo "<script language='javascript'>alert('modification avec success'); </script>";
              
                }
                else {
                   echo "<script language='javascript'>alert('modification échoué'); </script>"; 
                }
            
            
                    
        }        
    }
    
    public function GestionCollaborateur(){
         $sql = mysql_query("select * from collaborateur");
         echo "<table border='1'> <CAPTION> GESTION COLLABORATEUR </CAPTION>  <th>login</th> <th>mot de passe</th> <th>nom</th> <th>prenom</th> <th>service</th> <th>email</th> <th>suppression</th> <th>modification</th>";
         while($row = mysql_fetch_array($sql))
  {
  echo "<tr><td>".$row['login'] . "</td><td>" . $row['motdepasse']."</td><td>".$row['nom']."</td><td>".$row['prenom']."</td><td>".$row['service']."</td><td>".$row['email']."</td>";
   $login1 = $row['login'];
   echo "<td><a href='supprimercol.php?login2=$login1'>supprimer</a></td>";
   echo "<td><a href='modifiercol.php?login2=$login1'>modifier</a></td></tr> ";
    
  }
  echo'</table>';
        
    }
    
    public function SupprimerCollaborateur(){
        if (isset($_GET['login2']))
        {
            $login3 = $_GET['login2'];
       $sql = mysql_query("delete from collaborateur where login='$login3'"); 
        if ($sql)
        {
           echo "<script language='javascript'>alert('supprimé avec success'); </script>";
          
        }
        else {
                        echo "<script language='javascript'>alert('suppression échoué'); </script>";}
    }}
    
    public function ModifierCollaborateur() {
        
        
        if (isset($_GET['login2']) && isset($_POST['logincol']) && isset($_POST['motdepassecol']) && isset($_POST['nomcol']) && isset($_POST['prenomcol']) && isset($_POST['service'])&& isset($_POST['mailcol']))
        {
            $login3 = $_GET['login2'];
            $login = $_POST['logincol'];
            $motdepasse = $_POST['motdepassecol'];
            $nom = $_POST['nomcol'];
            $prenom = $_POST['prenomcol'];
            $service = $_POST['service'];
            $mail = $_POST['mailcol'];
           
            
             $sql = mysql_query("update collaborateur set login='$login',motdepasse='$motdepasse',nom='$nom',prenom='$prenom',service='$service',email='$mail' where login='$login3'");
            if ($sql){
                echo "<script language='javascript'>alert('modification avec success'); </script>";
                }
                else {
                   echo "<script language='javascript'>alert('modification échoué'); </script>"; 
                }
        }
        
    }
    
    public function AjouterCollaborateur() {
        
         if (isset($_POST['logincol1'])&& isset($_POST['motdepassecol1']) && isset($_POST['nomcol1']) && isset($_POST['prenomcol1']) && isset($_POST['service1']) && isset($_POST['mailcol1']))
        {
            $login = $_POST['logincol1'];
            $motdepasse = $_POST['motdepassecol1'];
            $nom = $_POST['nomcol1'];
            $prenom = $_POST['prenomcol1'];
            $service = $_POST['service1'];
            $mail = $_POST['mailcol1'];
            
            $sql = mysql_query("insert into collaborateur values('$login','$motdepasse','$nom','$prenom','$service','$mail')");
            if ($sql){
                echo "<script language='javascript'>alert('ajout avec success'); </script>";
                }
                else {
                   echo "<script language='javascript'>alert('ajout échoué'); </script>"; 
                }
            
        
    }

}
 public function GestionManager(){
         $sql = mysql_query("select m.login,m.motdepasse,m.nom,m.prenom,m.email,s.nomservice from manager m inner join services s on m.idservice=s.id");
         echo "<table border='1'><CAPTION>GESTION MANAGER</CAPTION>  <th>login</th> <th>mot de passe</th> <th>nom</th> <th>prenom</th> <th>nom service</th> <th>email</th> <th>suppression</th> <th>modification</th> ";
         while($row = mysql_fetch_array($sql))
  {
  echo "<tr><td>".$row['login'] . "</td><td>" . $row['motdepasse']."</td><td>".$row['nom']."</td><td>".$row['prenom']."</td><td>".$row['nomservice']."</td><td>".$row['email']."</td>";
   $login1 = $row['login'];
 
   echo "<td><a href='supprimerman.php?login2=$login1'>supprimer</a> </td>";
   echo "<td><a href='modifierman.php?login2=$login1'>modifier</a> </td></tr>";
    
      

  }
     echo '</table>';    
    }
    
     public function AjouterManger() {
         $tab = array();
        
         if (isset($_POST['loginman1'])&& isset($_POST['motdepasseman1']) && isset($_POST['nomman1']) && isset($_POST['prenomman1']) && isset($_POST['services1']) && isset($_POST['mailman1']))
        {
            $login = $_POST['loginman1'];
            $motdepasse = $_POST['motdepasseman1'];
            $nom = $_POST['nomman1'];
            $prenom = $_POST['prenomman1'];
            $mail = $_POST['mailman1'];
           $checkBox = $_POST['services1'];
    for($i=0; $i<sizeof($checkBox); $i++)
    {//{$tab[]=$checkBox[$i];}
    //$servicestab = implode(",", $tab);
            $sql0 = mysql_query("insert into services (nomservice,loginmanager) values ('$checkBox[$i]','$login')");
            $idservice= mysql_insert_id();
            $sql1 = mysql_query("insert into manager(login,motdepasse,nom,prenom,idservice,email) values('$login','$motdepasse','$nom','$prenom','$idservice','$mail')");
            
  }
            if ($sql1 && $sql0 ){
                echo "<script language='javascript'>alert('ajouté avec success'); </script>";
                }
                else {
                   echo "<script language='javascript'>alert('ajouté échoué'); </script>"; 
                }
            
        
    }

}

 public function ModifierManger() {
        
     $tab = array();
    
     
     if (isset($_GET['login2']) && isset($_POST['loginman']) && isset($_POST['motdepasseman']) && isset($_POST['nomman']) && isset($_POST['prenomman']) && isset($_POST['services'])&& isset($_POST['mailman']))
        {
            $login3 = $_GET['login2'];
          
             $mod = new Modification();
             $mod->setMan($login3);
            $login = $_POST['loginman'];
            $motdepasse = $_POST['motdepasseman'];
            $nom = $_POST['nomman'];
            $prenom = $_POST['prenomman'];
            $mail = $_POST['mailman'];
            
            
           $checkBox = $_POST['services'];
    for($i=0; $i<sizeof($checkBox); $i++)
    { //{$tab[]=$checkBox[$i];  
        //$servicestab = implode(",", $tab);
            
            // $sql = mysql_query("update manager set login='$login',motdepasse='$motdepasse',nom='$nom',prenom='$prenom' where login='$login3'");
       $sql1 = mysql_query("insert into services (nomservice,loginmanager) values ('$checkBox[$i]','$login')");
       $idservice= mysql_insert_id();
        $sql2 = mysql_query("insert into manager (login,motdepasse,nom,prenom,idservice,email) values ('$login','$motdepasse','$nom','$prenom','$idservice','$mail')");
        $sql3 = mysql_query("delete from manager where login='$login3'");
       $sql4 = mysql_query("delete from services where loginmanager='$login3'"); 
        
            
    }
    
    
             if ($sql1 && $sql2 && $sql3 && $sql4){
                echo "<script language='javascript'>alert('modification avec success'); </script>";
                }
                else {
                   echo"<script language='javascript'>alert('modification échoué'); </script>"; 
                }
        }
        
    }
    
      public function SupprimerManager(){
        if (isset($_GET['login2']))
        {
            $login3 = $_GET['login2'];
       $sql = mysql_query("delete from manager where login='$login3'");
       $sql1 = mysql_query("delete from services where loginmanager='$login3'"); 
        if ($sql && $sql1)
        {
           echo "<script language='javascript'>alert('supprimé avec success'); </script>";
          
        }
        else {
                        echo "<script language='javascript'>alert('suppression échoué'); </script>";}
    }}
    
public function PassageMan() {
    
    if (isset($_GET['login2'])){
    $login4 = $_GET['login2'];
     $modification = mysql_query("update modification set man='$login4' where id='man'");
    
        
    }
    
}

public function PassageCol() {
    
if (isset($_GET['login2']))    
{ $login4 = $_GET['login2'];

  mysql_query("update modification set col='$login4' where id='col'");
}   

}
}
?>
